int[] prefix = newint[n]; int[] suffix = newint[n]; for (intk=0; k < n; k++) { Strings= io.next();
for (inti=0; i < s.length() && prefix[k] < t.length(); i++) { if (s.charAt(i) == t.charAt(prefix[k])) { prefix[k]++; } }
for (inti=0; i < s.length() && suffix[k] < t.length(); i++) { if (s.charAt(s.length() - 1 - i) == t.charAt(t.length() - 1 - suffix[k])) { suffix[k]++; } } }
Arrays.sort(suffix);
longans=0L; for (inti=0; i < n; i++) { intlo=0, hi = n - 1; while (lo <= hi) { intmid= lo + (hi - lo) / 2; if (prefix[i] + suffix[mid] >= t.length()) hi = mid - 1; else lo = mid + 1; } ans += n - lo; } io.println(ans); }
publicstaticvoidsolve() { intn= io.nextInt(), m = io.nextInt();
int[] in = newint[n]; List<int[]>[] g = newList[n]; Arrays.setAll(g, k -> newArrayList<>()); for (inti=0; i < m; i++) { intu= io.nextInt() - 1, v = io.nextInt() - 1, b = io.nextInt(), c = io.nextInt(); g[u].add(newint[]{v, b, c}); in[v]++; }
doublelo=0, hi = 1e4; while (hi - lo >= 1e-10) { doublemid= lo + (hi - lo) / 2; if (check(g, in.clone(), mid)) lo = mid; else hi = mid; } io.println(lo); }
dist[0] = 0; for (intu=0; u < n; u++) { for (int[] t : g[u]) { intv= t[0], b = t[1], c = t[2]; if (dist[v] < dist[u] + b - c * x) { dist[v] = dist[u] + b - c * x; } } }